<?php
header("Content-type: text/plain; charset=utf-8", true);

if ($_SERVER["REQUEST_METHOD"] == "GET" && isset($_GET["service-source"])) {
    echo file_get_contents(__FILE__);
    return;
}

session_start();

require_once("lib/jsonss.php");

class SourceService extends JSONSSService {
    public function CreateMessage($p) {
        if (!isset($_SESSION["ChainedServices.Message"]))
            $_SESSION["ChainedServices.Message"] = "A Message from Source to Drain";
        return $_SESSION["ChainedServices.Message"];
    }

    public function __construct() {
        $this->add_method("CreateMessage", "createmsg");
    }
}

$server = new JSONSSServer();
$server->add_service(new SourceService(), "SourceService", "source-service");
$server->process_request();

session_commit();
